Uec3.InviteCompanyWindow = Ext.extend(Ext.app.Module, {
	id : 'inviteCompany',
	type : 'common/inviteCompany',

	/**
	 * Initialize this module. This function is called at startup (page
	 * load/refresh).
	 */
	init : function(initParams) {

	},

	getComponents : function(rowIndex) {

		var sendEmailForm;
		var email_ajax;

		var componentInitsInvite = function() {

			sendEmailForm = new Ext.form.FormPanel({
						labelAlign : 'right',
						frame : true,
						width : 400,
						height : 160,
						url : '',
						defaults : {
							width : 175,
							style : "margin-top:20px;",
							labelStyle : "margin-top:20px"
						},
						items : [

						{
									fieldLabel : '填写email',
									xtype : 'textfield',

									name : 'email',
									vtype : 'email',
									vtypeText : '请填写正确的邮箱格式',
									allowBlank : false,
									blankText : '公司邮箱不能为空'

								}

						],
						buttons : [{
							text : '发送邮件',
							handler : function() {

								if (!sendEmailForm.getForm().isValid()) {

									Ext.Msg.alert("提示", "表单校验未通过");

									return;

								}

								var acceptEmail = sendEmailForm.getForm()
										.findField('email').getValue();

								email_ajax.request({
											url : Uec3.App.Constants.homeUrl
													+ '/company/invitation!invite.do?',
											success : function(res) {
												var result = Ext
														.decode(res.responseText);
												if (result.success == "OK") {

													Ext.Msg.alert('提示', "发送成功");
												}

												else {

													Ext.Msg.alert("提示",
															result.failure);
												}

											},

											failure : function(res) {

												Ext.Msg.alert('失败',
														"网络出现异常，请重先连接");

											},

											params : {
												acceptEmail : acceptEmail
											}

										});
							}

						}, {
							text : '重置',

							handler : function() {

								sendEmailForm.getForm().reset();

							}

						}],

						buttonAlign : 'center'

					});

			// 增加员工
			email_ajax = new Ext.data.Connection();

		};

		var controlInviteEvent = function() {

			email_ajax.on('beforerequest', function() {

						Ext.MessageBox.wait("发送邮件中...", "提示");

					});
			email_ajax.on('requestcomplete', function() {

						Ext.MessageBox.hide();

					});
		};

		componentInitsInvite();

		controlInviteEvent();

		return sendEmailForm;

	},

	/**
	 * Create this modules window here.
	 */
	createWindow : function() {
		var desktop = this.app.getDesktop();
		var win = desktop.getWindow('inviteCompany');
		if (!win) {
			win = desktop.createWindow({
						id : 'inviteCompany',
						title : '邀请公司加入',
						width : 400,
						height : 160,
						autoScroll : true,
						iconCls : 'acc-icon',
						shim : false,
						animCollapse : false,
						constrainHeader : true,
						maximizable : false,
						resizable : false,
						taskbuttonTooltip : "邀请公司加入",
						layout : "fit",
						tools : [{
									id : 'refresh',
									handler : Ext.emptyFn,
									scope : this
								}],
						items : [this.getComponents()]
					});

		}
		win.show();

	}
});